<?php
declare (strict_types = 1);

namespace app\model;

use app\common\TencentIm;
use app\tool\Date;
use think\Model;

/**
 * @property bool $isread 是否已读:0=未读,1=已读
 * @property int $id
 * @property int $to_users_id
 * @property int $users_id
 * @property string $createtime
 * @property-read \app\model\Users $to_users
 * @property-read \app\model\Users $users
 * @property-read \app\model\UsersFollow[] $friends
 * @property-read mixed $create_time
 * @mixin \think\Model
 */
class UsersFollow extends Model
{
    protected $createTime = 'createtime';

    public static function onAfterInsert(Model $model): void
    {
	    $TencentIm = TencentIm::getInstance();
	    $TencentIm->send_msg('',$model->to_users_id,[['MsgType'=>'TIMCustomElem','MsgContent'=>['Text'=>'']]],json_encode(['data' => '', 'action' => 'notice']),['NoUnread']);
    }

    function users()
    {
        return $this->belongsTo(Users::class,'users_id');
    }

    function toUsers()
    {
        return $this->belongsTo(Users::class,'to_users_id');
    }

    function getCreateTimeAttr($value)
    {
        return Date::human($value);
    }

    function friends()
    {
        return $this->hasMany(UsersFollow::class,'users_id','to_users_id');
    }
}
